View Javadoc

1   // InflaterInputStreamWrapper.java, created Thu Jul  4  4:50:04 2002 by joewhaley
2   // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package joeq.ClassLib.Common.java.util.zip;
5   
6   /***
7    * InflaterInputStreamWrapper
8    *
9    * @author  John Whaley <jwhaley@alum.mit.edu>
10   * @version $Id: InflaterInputStreamWrapper.java 1451 2004-03-09 06:27:08Z jwhaley $
11   */
12  public class InflaterInputStreamWrapper extends java.util.zip.InflaterInputStream {
13      private boolean isClosed;
14      private boolean eof;
15      private final ZipFile zf;
16      public InflaterInputStreamWrapper(ZipFile zf, java.io.InputStream in, java.util.zip.Inflater inflater) {
17          super(in, inflater);
18          this.zf = zf;
19          this.isClosed = false; this.eof = false;
20      }
21      public void close() throws java.io.IOException {
22          if (!this.isClosed) {
23              zf.releaseInflater0(inf);
24              in.close();
25              isClosed = true;
26          }
27      }
28      protected void fill() throws java.io.IOException {
29          if (eof) throw new java.io.EOFException("Unexpected end of ZLIB input stream");
30          len = this.in.read(buf, 0, buf.length);
31          if (len == -1) {
32              buf[0] = 0;
33              len = 1;
34              eof = true;
35          }
36          inf.setInput(buf, 0, len);
37      }
38      public int available() throws java.io.IOException {
39          if (super.available() != 0) return this.in.available();
40          return 0;
41      }
42      
43  }